package com.swinginwind.flexutils.functions
{
	import mx.collections.ArrayCollection;
	import mx.collections.IList;
	
	/**
	 * @author jimmy
	 * @E-mail: swinginwind@gmail.com
	 * @version 1.0.0
	 * 创建时间：2013-6-7 下午12:07:35
	 * 
	 */
	public class UtilsCollection
	{
		public function UtilsCollection()
		{
		}
		
		
		public static function clone(source:IList):IList
		{
			if(source == null)
				return null;
			return spliceList(source, 0, source.length - 1);
		}
		
		
		public static function spliceList(source:IList, start:int, end:int, allowReverse:Boolean = false):IList
		{
			var result:IList = null;
			if(source == null || source.length == 0)
				return null;
			if(allowReverse)
			{
				if(start > end)
				{
					if(start >= source.length)
						start = source.length - 1;
					result = new ArrayCollection();
					for(var i:int=start;i>=end;i--)
					{
						if(i >= 0)
							result.addItem(source[i]);
					}
					return result;
				}
				else
				{
					return spliceList(source, start, end);
				}
			}
			else
			{
				if(start > end || start >= source.length)
					return null;
				if(end >= source.length)
					end = source.length - 1;
				result = new ArrayCollection();
				for(var j:int=start;j<=end;j++)
				{
					if(j >= 0)
						result.addItem(source[j]);
				}
				return result;
			}
		}
	}
}